Java JavaScript Python C# C C++ Go Kotlin PHP Swift R Ruby TypeScript Scala SQL Perl rust VisualBasic Matlab Julia

Java Operators

Assignment operator

About assignment operators Assignment operators are used to assign a value to a variable. The following are the assignment operators in Java: Assignment (=): Assigns the value of the expression on the right side of the operator to the variable on the left side of the operator. Addition assignment (+=): Adds the value of the expression on the right side of the operator to the variable on the left side of the operator and assigns the result to the variable. Subtraction assignment (-=): Subtracts the value of the expression on the right side of the operator from the variable on the left side of the operator and assigns the result to the variable. *Multiplication assignment (=): Multiplies the value of the expression on the right side of the operator by the variable on the left side of the operator and assigns the result to the variable. Division assignment (/=): Divides the variable on the left side of the operator by the value of the expression on the right side of the operator and assigns the result to the variable. Modulus assignment (%=): Modifies the variable on the left side of the operator by the value of the expression on the right side of the operator and assigns the result to the variable. Bitwise AND assignment (&=): Performs a bitwise AND operation on the variable on the left side of the operator and the value of the expression on the right side of the operator and assigns the result to the variable. Bitwise OR assignment (|=): Performs a bitwise OR operation on the variable on the left side of the operator and the value of the expression on the right side of the operator and assigns the result to the variable. Bitwise XOR assignment (^=): Performs a bitwise XOR operation on the variable on the left side of the operator and the value of the expression on the right side of the operator and assigns the result to the variable. Left shift assignment (<<=): Shifts the bits of the variable on the left side of the operator to the left by the number of bits specified by the value of the expression on the right side of the operator and assigns the result to the variable. Right shift assignment (>>=): Shifts the bits of the variable on the left side of the operator to the right by the number of bits specified by the value of the expression on the right side of the operator and assigns the result to the variable. Here are some examples of how assignment operators are used in Java:
Java - Assignment operator
int x = 10; int y = 20; // Assign the value of y to x x = y; // Add 10 to x x += 10; // Subtract y from x x -= y; // Multiply x by 2 x *= 2; // Divide x by y x /= y; // Modulus of x by y x %= y; // Bitwise AND x with y x &= y; // Bitwise OR x with y x |= y; // Bitwise XOR x with y x ^= y; // Left shift x by 2 bits x <<= 2; // Right shift x by 2 bits x >>= 2;
The operands of an assignment operator can be of any type, including primitive types, reference types, and expressions. The result of an assignment operation is the value of the variable on the left side of the operator. Here are some other important points to keep in mind about assignment operators in Java: Assignment operators are evaluated from left to right. The operands of an assignment operator must be of compatible types. The result of an assignment operation is the value of the variable on the left side of the operator.

  📌TAGS

★Assignment operator ★ operator ★ java ★ operator in java

Tutorials